package com.ror.java.se.collection.set;

public class StudentWithScore implements Comparable<StudentWithScore> {
    private String name;
    private int age;
    private int langScore;
    private int mathScore;
    private int engScore;

    public StudentWithScore() {
    }

    public StudentWithScore(String name, int age, int langScore, int mathScore, int engScore) {
        this.name = name;
        this.age = age;
        this.langScore = langScore;
        this.mathScore = mathScore;
        this.engScore = engScore;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     *
     * @return langScore
     */
    public int getLangScore() {
        return langScore;
    }

    /**
     * 设置
     *
     * @param langScore
     */
    public void setLangScore(int langScore) {
        this.langScore = langScore;
    }

    /**
     * 获取
     *
     * @return mathScore
     */
    public int getMathScore() {
        return mathScore;
    }

    /**
     * 设置
     *
     * @param mathScore
     */
    public void setMathScore(int mathScore) {
        this.mathScore = mathScore;
    }

    /**
     * 获取
     *
     * @return engScore
     */
    public int getEngScore() {
        return engScore;
    }

    /**
     * 设置
     *
     * @param engScore
     */
    public void setEngScore(int engScore) {
        this.engScore = engScore;
    }


    public String toString() {
        return "AdvancedStudent{name = " + name + ", age = " + age + ", langScore = " + langScore + ", mathScore = " + mathScore + ", engScore = " + engScore + "}";
    }

    @Override
    public int compareTo(StudentWithScore o) {
        //按照总分从高到低
        //如果总分一样，按照语文成绩排
        //如果语文一样，按照数学成绩排
        //如果数学成绩一样，按照英语成绩排
        //如果英文成绩一样，按照年龄排
        //如果年龄一样，按照姓名的字母顺序排
        //如果都一样，认为是同一个学生，不存。
        int sum1 = this.getEngScore() + this.getLangScore() + this.getMathScore();
        int sum2 = o.getEngScore() + o.getLangScore() + o.getMathScore();
        int del = sum1 - sum2;
        del = del == 0 ? this.getLangScore() - o.getLangScore() : del;
        del = del == 0 ? this.getMathScore() - o.getMathScore() : del;
        //总分一样语文一样数学一样，英语自然也一样
//        del = del == 0 ? this.getEngScore() - o.getEngScore() : del;
        del = del == 0 ? this.getAge() - o.getAge() : del;
        del = del == 0 ? this.getName().compareTo(o.getName()) : del;
        return del;
    }
}
